<?php
error_reporting(E_ALL ^ E_NOTICE);
include_once($_SERVER['DOCUMENT_ROOT'] . '/htqlmba/models/m_tram.php');
include_once($_SERVER['DOCUMENT_ROOT'] . '/htqlmba/controls/c_capNhatTram.php');
?>

<script type="text/javascript">
// funtion lay gia tri tu radio button "chon"
    function getValue(id) {
        document.capnhattram.txtmatram.value = document.getElementById("matram" + id).innerHTML;
        document.capnhattram.txttentram.value = document.getElementById("tentram" + id).innerHTML;
        document.capnhattram.txtdiachitram.value = document.getElementById("diachitram" + id).innerHTML;

        // chuyen mau cac textfield tendv,diachidv,lienhedv thanh mau trang', va cho phep sua doi thong tin
        document.capnhattram.txtmatram.readOnly = true;
        document.capnhattram.txtmatram.style.backgroundColor = '#cccccc';
        document.capnhattram.txttentram.style.backgroundColor = '#FFFFFF';
        document.capnhattram.txtdiachitram.style.backgroundColor = '#FFFFFF';

        document.capnhattram.btnsuatram.disabled = false;
        document.capnhattram.btnxoatram.disabled = false;
        document.capnhattram.btnthemtram.disabled = true;

    }

// fuction hien bang xac nhan truoc khi xoa don vi
    function confirmDelete() {
        if (confirm("Bạn có chắc muốn xóa trạm này không?")) {
            return true;
        }
        return false;
    }
    function xoadulieu() {
        document.capnhattram.txtmatram.readOnly = false;
        document.capnhattram.txttentram.disabled = false;
        document.capnhattram.txtdiachitram.disabled = false;

        document.capnhattram.btnthemtram.disabled = false;

        document.capnhattram.txtmatram.style.backgroundColor = '#ffffff';
		document.capnhattram.txtmatram.value ="";
        document.capnhattram.txttentram.value = "";
        document.capnhattram.txtdiachitram.value = "";
    }



</script>

<!doctype html>
<html>
    <head>
        <meta charset=utf-8 />
        <title>Cập nhật trạm</title>
        <link href="/htqlmba/libraries/css/capnhatdv.css" type="text/css" rel="stylesheet">
    </head>

    <body>
        <div class="bodyStyle">
            <form name="capnhattram" method="post" action="">
                <!-- bang hien thi -->  
                <table align="center" class="font" width="500" border="0" cellspacing="1" cellpadding="2">
                    <tr bgcolor="#dae9f3">

                        <td align=center class=TableHeader1  height="35" > &equiv; Cập Nhật Trạm</td>
                    </tr>
                    <tr bgcolor="#dae9f3">
                        <td colspan="3" valign="top"><table width="793" border="0" align="center" >

                                <tr>
                                    <td width="79" height="25" class="TableField2">Mã trạm</td>
                                    <td align="left" class="error" ><input name="txtmatram" type="text" id="txtmatram"  size="10" maxlength="100" ><?php echo $matramErr; ?></td>
                                </tr>
                                <tr>
                                    <td height="25" class="TableField2">Tên trạm</td>
                                    <td class="error"><input name="txttentram" type="text" id="txttentram"   size="70" maxlength="50" ><?php echo $tentramErr; ?></td>
                                </tr>        

                                <tr>
                                    <td height="25" class="TableField2">Địa chỉ trạm</td>
                                    <td><input name="txtdiachitram" type="text" id="txtdiachitram"  size="70" maxlength="50" ></td>
                                </tr>
                                <tr>
                                    <td colspan="2" class="btn_x" id="btn_x" >
                                        <input type="submit" name="btnthemtram" id="btnthemtram" value="Thêm trạm">
                                        <input type="button" name="btnreset" id="btnreset" value="Xóa dử liệu nhập vào" onClick="xoadulieu()">
                                        <input type="submit" name="btnsuatram" id="btnsuatram" value="Sửa trạm" disabled="true">
                                        <input type="submit" name="btnxoatram" id="btnxoatram" value="Xóa trạm"  disabled="true" onClick="return confirmDelete()">
                                    </td>
                                </tr>
                            </table></td>
                    </tr>
                </table>
                </br>

                <!-- lay du lieu tu bang don vi va hien thi -->
                <?php
                $tram = new Tram();
                $result = $tram->dsTram();
                echo "<table align='center' width='900' border='0' cellspacing='0' cellpadding='0' ";
                echo "<tr >";
                echo "<td align='center' class='TableHeader1'> &equiv;  Danh sách trạm</td>";
                echo "</tr>";
                echo "<tr >";
                echo "<td colspan='3' valign='top'><table width='900' border='0' cellpadding='0' cellspacing='0'>";
                echo "<tr>";
                echo "<td width='30' align='center' class='TableHeader' >STT</td>";
                echo "<td width='400' align='center' class='TableHeader' >Mã trạm </td>";
                echo "<td width='900' align='center' class='TableHeader' >Tên trạm </td>";
                echo "<td width='800' align='center' class='TableHeader'>Địa chỉ trạm </td>";
                echo "</tr>";
                $num = mysql_num_rows($result);
                $i = 0;
                echo "<tbody style='display:none;'>";
                while ($row = mysql_fetch_array($result)) {

                    $i++;
                    if ($i % 2 == 0) {
                        echo "</tbody>";
                        echo "<tr onClick='getValue($i);'>";
                        echo "<td align='center' class='TableField2'>" . $i . "</td>";
                        echo "<td  align='center' class='TableField2'><div id='matram$i'>" . $row['MA_TRAM'] . "</div></td>";
                        echo "<td  align='left' class='TableField2'><div id='tentram$i'>" . $row['TEN_TRAM'] . "</div></td>";
                        echo "<td  align='left' class='TableField2'><div id='diachitram$i'>" . $row['DIA_CHI_TRAM'] . "</div></td>";
                       
                        echo "</tr>";
                    } else {
                        echo "</tbody>";
                        echo "<tr onClick='getValue($i);'>";
                        echo "<td align='center' class='TableField'>" . $i . "</td>";
                        echo "<td  align='center' class='TableField'><div id='matram$i'>" . $row['MA_TRAM'] . "</div></td>";
                        echo "<td  align='left' class='TableField'><div id='tentram$i'>" . $row['TEN_TRAM'] . "</div></td>";
                        echo "<td  align='left' class='TableField'><div id='diachitram$i'>" . $row['DIA_CHI_TRAM'] . "</div></td>";
                        
                        echo "</tr>";
                    }
                }
                echo "</tbody>";

                echo "<tr>";
                echo "<td align='left' colspan='9'><span style=' color:#008000'>Tổng số trạm: $num";

                echo "</span></td>";
                echo "<td align='right' colspan='2'><font color='green'>";
                echo "</font></td>";
                echo "</tr>";
                echo "</table></td>";
                echo "</tr>";
                echo "</table>";
                //}
//}
                ?>
            </form>
            <!-- het bang -->
        </p>

        <p>&nbsp;


        </p>
    </div>
</body>
</html>
